/*
* 优惠券领取记录
* @Author: Li Yujie
* @Date: 2020-11-14
*/
<template>
    <div class="wrapper">
        <!--筛选表单-->
        <div class="filter-view">
            <el-radio-group
                v-model="filterData.status"
                size="small"
                style="margin-right: 24px"
                @change="getTableData(1)"
            >
                <el-radio-button
                    v-for="item in useStatusList"
                    :label="item.value"
                    :key="item.value"
                >
                    {{ item.label }}
                </el-radio-button>
            </el-radio-group>
            <div class="header-new-box">
                <p class="header-new-box-title">领券渠道</p>
                <el-select
                    v-model="filterData.channel"
                    placeholder="全部"
                    size="small"
                    clearable
                    @change="getTableData(1)"
                >
                    <el-option
                        v-for="item in channelList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    />
                </el-select>
            </div>
            <div class="header-new-box">
                <p class="header-new-box-title">用户信息</p>
                <el-input
                    placeholder="请输入用户昵称/手机号"
                    v-model="filterData.keyword"
                    suffix-icon="el-icon-search"
                    size="small"
                    clearable
                    @blur="getTableData(1)"
                    @keydown.enter.native="getTableData(1)"
                />
            </div>
        </div>
        <!--/筛选表单-->

        <!-- table -->
        <el-table
            :data="tableData"
            height="100%"
            style="width: 100%;"
            ref="tempLateName"
        >
            <el-table-column
                type="index"
                label="序号"
                width="80"
                align="center"
            />
            <el-table-column
                prop="true_name"
                label="领券用户昵称"
                show-overflow-tooltip
                align="left"
                :formatter="emptyFormatter"
            />
            <el-table-column
                prop="phone"
                label="用户手机号"
                show-overflow-tooltip
                align="center"
                :formatter="emptyFormatter"
            />
            <el-table-column
                prop="school_name"
                label="学校名称"
                show-overflow-tooltip
                align="left"
                :formatter="emptyFormatter"
            />
            <el-table-column
                prop=""
                label="领券渠道"
                show-overflow-tooltip
                align="center"
                :formatter="emptyFormatter"
                width="100"
            >
                <template slot-scope="scope">
                    {{ scope.row.channel | channelName }}
                </template>
            </el-table-column>
            <el-table-column
                prop=""
                label="领券时间"
                show-overflow-tooltip
                align="center"
                width="400"
            >
                <template slot-scope="scope">
                    {{ scope.row.receive_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                </template>
            </el-table-column>
            <el-table-column
                prop=""
                label="使用状态"
            >
                <template slot-scope="scope">
                    <div class="status-wrapper">
                        <div
                            :class="['status-dot',scope.row.status === 0 ? 'warning' : (scope.row.status === 1 ? 'success' : 'normal')]"/>
                        <div class="status-name">{{ scope.row.status | statusName }}</div>
                    </div>
                </template>
            </el-table-column>
        </el-table>
        <!-- /table -->

        <!-- /分页 -->
        <div class="pagination-wrapper clearfix">
            <el-pagination
                layout="total, prev, pager, next, jumper"
                :current-page.sync="page.now_page"
                :total="page.total_count"
                :page-size="page.page_size"
                @current-change="getTableData"
            />
        </div>
    </div>
</template>

<script>
export default {
    name: "ReceiveRecord",
    props: {
        couponNo: {
            type: String,
            required: true
        },
    },
    data() {
        return {
            filterData: {
                filterType: '1',
                keyword: '',
                channel: '',
                // 使用状态
                status: ''
            },
            tableData: [],
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
            useStatusList: [
                {label: '全部', value: ''},
                {label: '未使用', value: 0},
                {label: '已使用', value: 1},
                {label: '已过期', value: 2}
            ],
            channelList: [
                {label: 'H5扫码', value: 'h5'},
                {label: '安卓', value: 'android'},
                {label: 'IOS', value: 'ios'},
                {label: '系统赠送', value: 'system'},
            ]
        };
    },
    filters: {
        statusName(val) {
            switch (val) {
                case 0:
                    return '未使用';
                case 1:
                    return '已使用';
                case 2:
                    return '已过期';
                default:
                    return '';
            }
        },
        channelName(val) {
            switch (val) {
                case 'ios':
                    return 'IOS';
                case 'android':
                    return '安卓';
                case 'h5':
                    return 'H5扫码';
                case 'system':
                    return '系统赠送';
                default:
                    return '';
            }
        }
    },
    mounted() {
        this.getTableData();
    },
    methods: {

        /**
         * 获取表格数据
         * @param page
         */
        getTableData(page) {
            let params = {...this.filterData};

            params.coupon_no = this.couponNo;
            params.page_id = page || this.page.now_page;
            this.$post('/student/shop_goods_coupon%5Cget_receive_list', params, resp => {
                if (resp.code === 1) {
                    this.tableData = resp.data.list;
                    this.page = resp.data.page;
                } else {
                    this.$notify({
                        title: '失败',
                        message: resp.msg,
                        duration: 2000,
                        type: 'warning'
                    });
                }
            });
        },
        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        },
    }
};
</script>

<style scoped lang="less">
.wrapper {
    display: flex;
    height: calc(100% - 24px);
    width: calc(100% - 48px);
    flex-direction: column;
    position: relative;
    margin: 0 24px 24px;
    background: #fff;
    box-sizing: border-box;

    /*筛选*/
    .filter-view {
        margin: 6px 0 10px;
        display: flex;
        .header-new-box {
            display: flex;
            align-items: center;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #333333;
            white-space: nowrap;
            margin-right: 24px;
            margin-bottom: 16px;

            &-title {
                margin-right: 16px;
                white-space: nowrap;
            }
        }
    }

    .status-wrapper {
        display: flex;
        align-items: center;

        .status-dot {
            width: 6px;
            height: 6px;
            border-radius: 50%;
            margin-right: 5px;

            &.success {
                background: #4CD964;
            }

            &.danger {
                background: #FF3030;
            }

            &.warning {
                background: #FFA72D;
            }

            &.normal {
                background: #C2C2C2;
            }
        }
    }

    /* 分页 */
    .pagination-wrapper {
        padding: 10px 32px;

        .el-pagination {
            float: right;
            padding: 0;
            background-color: transparent;
        }
    }
}
</style>
